<!DOCTYPE html>

<html lang="en">
<head>
    <meta charset="utf-8">
    <title>AssertJ Android by Square, Inc.</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="A set of AssertJ assertions geared toward testing Android." />
    <link href="http://fonts.googleapis.com/css?family=Roboto:regular,medium,thin,italic,mediumitalic,bold" rel="stylesheet" title="roboto">
    <link href="static/bootstrap.min.css" rel="stylesheet">
    <link href="static/bootstrap-responsive.min.css" rel="stylesheet">
    <link href="static/prettify.css" rel="stylesheet">
    <link href="static/app.css" rel="stylesheet">
</head>
<body>
<div class="container">
    <div class="row">
        <div class="span8 offset2 lead">
            <h1>AssertJ Android</h1>
            <h3>A set of AssertJ assertions geared toward testing Android.</h3>
            <ul class="unstyled">
                <li><a href="#download" class="btn btn-inverse btn-large">Download</a></li>
            </ul>
      </div>
    </div>
    <div class="row">
      <div class="span10 offset1">
        <p>Writing tests is not the most glamorous part of developing an Android application but it is an invaluable one. Using libraries like JUnit and AssertJ provide a great starting point for writing tests.</p>
        <p>This library is an extension of <a href="http://joel-costigliola.github.io/assertj/">AssertJ</a> which aims to make it even easier to test Android.</p>
      </div>
    </div>
    <div class="row examples section">
      <div class="span8 offset2">
        <h5>AssertJ Android</h5>
        <pre class="prettyprint">assertThat(view).isGone();</pre>
      </div>
    </div>
    <div class="row">
      <div class="span6 bad">
        <h5>Regular JUnit</h5>
        <pre class="prettyprint">assertEquals(View.GONE, view.getVisibility());</pre>
      </div>
      <div class="span6 bad">
        <h5>Regular AssertJ</h5>
        <pre class="prettyprint">assertThat(view.getVisibility()).isEqualTo(View.GONE);</pre>
      </div>
    </div>
    <div class="row section">
      <div class="span10 offset1">
        <p>When failing, the <em>AssertJ Android</em> assertion produces an output which allows you to immediately recognize the problem: <code>Expected visibility &lt;gone> but was &lt;invisible>.</code></p>
        <p>Compare that to the output of regular <em>AssertJ</em> <code>expected:&lt;[8]> but was:&lt;[4]></code> and regular <em>JUnit</em> <code>expected: &lt;8> but was: &lt;4></code> and you should immediately see the advantage.</p>
        <p>Because <em>AssertJ Android</em> offers assertions directly on objects rather than properties they can be chained together.</p>
      </div>
    </div>
    <div class="row examples section">
      <div class="span8 offset2">
        <h5>AssertJ Android</h5>
        <pre class="prettyprint">assertThat(layout).isVisible()
    .isVertical()
    .hasChildCount(4)
    .hasShowDividers(SHOW_DIVIDERS_MIDDLE);</pre>
      </div>
    </div>
    <div class="row">
      <div class="span6 bad">
        <h5>Regular JUnit</h5>
        <pre class="prettyprint">assertEquals(View.VISIBLE, layout.getVisibility());
assertEquals(VERTICAL, layout.getOrientation());
assertEquals(4, layout.getChildCount());
assertEquals(SHOW_DIVIDERS_MIDDLE, layout.getShowDividers());</pre>
      </div>
      <div class="span6 bad">
        <h5>Regular AssertJ</h5>
        <pre class="prettyprint">assertThat(layout.getVisibility()).isEqualTo(View.VISIBLE);
assertThat(layout.getOrientation()).isEqualTo(VERTICAL);
assertThat(layout.getChildCount()).isEqualTo(4);
assertThat(layout.getShowDividers()).isEqualTo(SHOW_DIVIDERS_MIDDLE);</pre>
      </div>
    </div>
    <div class="row section">
      <div class="span10 offset1">
        <p>Assertions exist for nearly every object that you would ever want to test, from <code>LinearLayout</code> to <code>ActionBar</code> to <code>Fragment</code> to <code>MenuItem</code>. Everything in the support library is included too.</p>
      </div>
    </div>
    <div class="row section">
      <div class="span10 offset1">
        <p>To get started writing tests add the following import:</p>
        <pre class="prettyprint">import static org.assertj.android.api.Assertions.assertThat;</pre>
      </div>
    </div>
    <div class="row section">
      <div class="span10 offset1">
        <h5 id="add-ons">Add-On Modules</h5>
        <p>Modules are also provided for the add-on Android libraries. Add the dependency (listed below) and use the following imports:</p>
        <ul>
          <li><p>support-v4</p><pre class="prettyprint">import static org.assertj.android.support.v4.api.Assertions.assertThat;</pre></li>
          <li><p>Google Play Services</p><pre class="prettyprint">import static org.assertj.android.playservices.api.Assertions.assertThat;</pre></li>
          <li><p>appcompat-v7</p><pre class="prettyprint">import static org.assertj.android.appcompat.v7.api.Assertions.assertThat;</pre></li>
          <li><p>mediarouter-v7</p><pre class="prettyprint">import static org.assertj.android.mediarouter.v7.api.Assertions.assertThat;</pre></li>
          <li><p>gridlayout-v7</p><pre class="prettyprint">import static org.assertj.android.gridlayout.v7.api.Assertions.assertThat;</pre></li>
          <li><p>cardview-v7</p><pre class="prettyprint">import static org.assertj.android.cardview.v7.api.Assertions.assertThat;</pre></li>
          <li><p>recyclerview-v7</p><pre class="prettyprint">import static org.assertj.android.recyclerview.v7.api.Assertions.assertThat;</pre></li>
          <li><p>pallete-v7</p><pre class="prettyprint">import static org.assertj.android.pallete.v4.api.Assertions.assertThat;</pre></li>
        </dl>
      </div>
    </div>
    <div class="row section">
      <div class="span10 offset1">
        <h5 id="extending">Extending</h5>
        <p>The provided assertions have also been designed to be extended for any custom controls you have developed.</p>
        <pre class="prettyprint">public class CustomLayout extends LinearLayout {
  public int getBehavior() {
    /* ... */
  }
}</pre>
        <p>Use the following pattern to set up your assertions.</p>
        <pre class="prettyprint">public class CustomLayoutAssert extends AbstractLinearLayoutAssert&lt;CustomLayoutAssert, CustomLayout> {
  public static CustomLayoutAssert assertThat(CustomLayout actual) {
    return new CustomLayoutAssert(actual);
  }

  public CustomLayoutAssert(CustomLayout actual) {
    super(actual, CustomLayoutAssert.class);
  }

  public CustomLayoutAssert hasSomeBehavior() {
    isNotNull();
    assertThat(actual.getBehavior())
        .overridingErrorMessage("Expected some behavior but was doing other behavior.")
        .isEqualTo(42)
    return this;
  }
}</pre>
        <p>Now static import <code>CustomLayoutAssert.assertThat</code> in your test classes.</p>
        <p>For more information about writing custom assertions see the <a href="http://joel-costigliola.github.io/assertj/assertj-core-custom-assertions.html">official documentation</a>.</p>
      </div>
    </div>
    <div class="row section">
      <div class="span10 offset1">
        <h5 id="download">Download</h5>
        <ul>
          <li><p>Android module:</p><pre class="prettyprint">androidTestCompile 'com.squareup.assertj:assertj-android:<span class="maven-version">1.0.0</span>'</pre></li>
          <li><p>support-v4 module:</p><pre class="prettyprint">androidTestCompile 'com.squareup.assertj:assertj-android-support-v4:<span class="maven-version">1.0.0</span>'</pre></li>
          <li><p>Google Play Services module:</p><pre class="prettyprint">androidTestCompile 'com.squareup.assertj:assertj-android-play-services:<span class="maven-version">1.0.0</span>'</pre></li>
          <li><p>appcompat-v7 module:</p><pre class="prettyprint">androidTestCompile 'com.squareup.assertj:assertj-android-appcompat-v7:<span class="maven-version">1.0.0</span>'</pre></li>
          <li><p>mediarouter-v7 module:</p><pre class="prettyprint">androidTestCompile 'com.squareup.assertj:assertj-android-mediarouter-v7:<span class="maven-version">1.0.0</span>'</pre></li>
          <li><p>gridlayout-v7 module:</p><pre class="prettyprint">androidTestCompile 'com.squareup.assertj:assertj-android-gridlayout-v7:<span class="maven-version">1.0.0</span>'</pre></li>
          <li><p>cardview-v7 module:</p><pre class="prettyprint">androidTestCompile 'com.squareup.assertj:assertj-android-cardview-v7:<span class="maven-version">1.0.0</span>'</pre></li>
          <li><p>recyclerview-v7 module:</p><pre class="prettyprint">androidTestCompile 'com.squareup.assertj:assertj-android-recyclerview-v7:<span class="maven-version">1.0.0</span>'</pre></li>
          <li><p>pallete-v7 module:</p><pre class="prettyprint">androidTestCompile 'com.squareup.assertj:assertj-android-pallete-v7:<span class="maven-version">1.0.0</span>'</pre></li>
        </ul>
      </div>
    </div>
    <div class="span12 foot">
        <a id="ribbon" href="https://github.com/square/assertj-android"><img src="static/ribbon.png" alt="Fork me on GitHub"></a>
        <p><a href="http://squareup.com"><img src="static/square.png" alt="by Square, Inc."></a></p>
    </div>
</div>
<script src="static/prettify.js"></script>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="static/jquery-maven-artifact.min.js"></script>
<script>
  prettyPrint();

  $.fn.artifactVersion('com.squareup.assertj', 'assertj-android', function(version, url) {
    $('.maven-version').text(version);
  });
</script>
</body>
</html>
